#!/usr/bin/env python
# -*- indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
# vi: set ts=4 sts=4 sw=4 set smarttab set expandtab
#http://www.careercup.com/question?id=14851686
#Facebook interview question

import random
import time

def random_arr(length = random.randint(10, 20), min = 0, max = 100):
    result = [random.randint(min, max) for i in range(length)]
    return result

def random_str(length = random.randint(10, 20), chars = None):
    a, A = ord('a'), ord('A')
    if not chars:
        chars = [chr(i + a) for i in range(26)] + [chr(i + A) for i in range(26)]
    candidates_length = len(chars)
    result = [chars[random.randint(0, candidates_length - 1)] for i in range(length)]
    return "".join(result)

def arr_to_str(arr):
    return "".join([chr(i + ord('a')) for i in arr])

def print_pass():
    print '\x1b[32m PASS \x1b[0m'

def print_fail():
    print '\x1b[31m FAIL \x1b[0m'

def time_profile(func):
    def timing_and_call(*args, **kwargs):
        start_time = time.time()
        try:
            return func(*args, **kwargs)
        finally:
            print func.__name__, ' running time: ', (time.time() - start_time) * 1000 , ' ms'
    return timing_and_call

def check_result(david, lobatt, args):
    david = david(*args)
    lobatt = lobatt(*args)
    if david != lobatt:
        print_fail()
        print "david", david
        print "lobatt", lobatt
    else:
        print_pass()
